<template>
  <div class="app-container">
    <div class="header">
      <div class="word">
        <div class="w1">
          原料出入库系统
        </div>
        <div class="w2">
          在原料出入库系统中你可以查看原料输出进入等基本信息，同时还可以实现查询原料出入口状态，添加原料出入口信息等功能，提供一套可行的出入口管理方案
        </div>
        <div class="w2">
          原料出入库系统是加工系统中重要的一环,它可以为我们提供原料出入库的信息，为下一步加工做准备
        </div>
      </div>
      <img class="imgDri" src="../static/13m58PIC9J3H7ixyNFfCw_PIC2018.png">
    </div>
    <div class="index">
      <div class="searchHead">
        <el-button type="primary" @click="dialogFormVisible = true">新增司机</el-button>
        <el-input v-model="input3" placeholder="请输入要查询的数据" class="searchIuput">
          <el-select slot="prepend" v-model="select" class="sel3" placeholder="请选择">
            <el-option label="司机id" value="id" />
            <el-option label="姓名" value="driverName" />
            <el-option label="驾驶证号" value="drivingLicenseNumber" />
          </el-select>
          <el-button slot="append" v-model="searchInf" icon="el-icon-search" @click="searchMes" />
        </el-input>
      </div>

      <el-dialog title="司机信息添加" :visible.sync="dialogFormVisible">
        <el-form class="form">
          <el-form-item class="item" label="姓名" :label-width="formLabelWidth">
            <el-input v-model="addMes.driverName" class="in" autocomplete="off" />
          </el-form-item>
          <el-form-item class="item" label="年龄" :label-width="formLabelWidth">
            <el-input v-model="addMes.age" class="in" autocomplete="off" />
          </el-form-item>
          <div class="sel">
            <el-select v-model="addMes.gender" class="sel2" placeholder="请选择性别">
              <el-option label="男" value="男" />
              <el-option label="女" value="女" />
            </el-select>
          </div>
          <el-form-item class="item" label="电话" :label-width="formLabelWidth">
            <el-input v-model="addMes.driverPhone" class="in" autocomplete="off" />
          </el-form-item>
          <div class="sel">
            <el-select v-model="addMes.driverStatus" class="sel2" placeholder="请选择状态">
              <el-option label="空闲" value="空闲" />
              <el-option label="忙碌" value="忙碌" />
              <el-option label="休假" value="休假" />
            </el-select>
          </div>
          <el-form-item class="item" label="身份证号" :label-width="formLabelWidth">
            <el-input v-model="addMes.identityCard" class="in" autocomplete="off" />
          </el-form-item>
          <el-form-item class="item" label="驾驶证号" :label-width="formLabelWidth">
            <el-input v-model="addMes.drivingLicenseNumber" class="in" autocomplete="off" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addDri()">确 定</el-button>
        </div>
      </el-dialog>

      <el-table :data="mes" type="" style="width: 100%">
        <el-table-column prop="staffName" label="质检员姓名" width="180" />
        <el-table-column prop="staffPosition" label="质检员职位" width="180" />
        <el-table-column prop="productName" label="产品名称" width="180" />
        <el-table-column prop="driverPhone" label="联系电话" width="180" />
        <el-table-column prop="drugResidue" label="检测状态" />
        <el-table-column prop="tinyCreateContent" label="微生物指标" />
        <el-table-column prop="weightGoods" label="产品吨数" />

        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" @click="mes[scope.$index].isShow = true">修改</el-button>
            <el-button type="text" style="color:red" @click="mes[scope.$index].isShowDel = true">删除</el-button>

            <el-dialog :modal-append-to-body="false" title="提示" :visible.sync="mes[scope.$index].isShowDel" width="30%">
              <span>确认要删除此条信息吗？</span>
              <span slot="footer" class="dialog-footer">
                <el-button @click="mes[scope.$index].isShowDel = false">取 消</el-button>
                <el-button type="primary" @click="driveDel(scope.$index)">确 定</el-button>
              </span>
            </el-dialog>

            <el-dialog :modal-append-to-body="false" title="修改信息" :visible.sync="mes[scope.$index].isShow">
              <el-form class="form">
                <el-form-item class="item" label="姓名" :label-width="formLabelWidth">
                  <el-input v-model="mes[scope.$index].driverName" autocomplete="off" />
                </el-form-item>
                <el-form-item class="item" label="年龄" :label-width="formLabelWidth">
                  <el-input v-model="mes[scope.$index].age" autocomplete="off" />
                </el-form-item>
                <div class="sel">
                  <el-select v-model="mes[scope.$index].gender" class="sel2" placeholder="请选择性别">
                    <el-option label="男" value="男" />
                    <el-option label="女" value="女" />
                  </el-select>
                </div>
                <el-form-item class="item" label="电话" :label-width="formLabelWidth">
                  <el-input v-model="mes[scope.$index].driverPhone" autocomplete="off" />
                </el-form-item>
                <div class="sel">
                  <el-select v-model="mes[scope.$index].driverStatus" class="sel2" placeholder="请选择状态">
                    <el-option label="空闲" value="空闲" />
                    <el-option label="忙碌" value="忙碌" />
                    <el-option label="休假" value="休假" />
                  </el-select>
                </div>
                <el-form-item class="item" label="身份证号" :label-width="formLabelWidth">
                  <el-input v-model="mes[scope.$index].identityCard" autocomplete="off" />
                </el-form-item>
                <el-form-item class="item" label="驾驶证号" :label-width="formLabelWidth">
                  <el-input v-model="mes[scope.$index].drivingLicenseNumber" autocomplete="off" />
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="mes[scope.$index].isShow = false">取 消</el-button>
                <el-button type="primary" @click="changeDriver(scope.$index)">确 定</el-button>
              </div>
            </el-dialog>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          :page-size="5"
          layout="prev, pager, next, jumper"
          :total="pageSize"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import request from '../../../utils/request'
export default {
  name: 'OutAndIn',
  data() {
    return {
      mes: [],
      dialogTableVisible: false,
      formLabelWidth: '120px',
      addMes: {
        'age': null,
        'driverName': null,
        'driverPhone': null,
        'driverStatus': null,
        'drivingAge': null,
        'drivingLicenseNumber': null,
        'gender': null,
        'id': null,
        'identityCard': null,
        'managementOfficeId': '3451'
      },
      dialogFormVisible: false,
      pageSize: null,
      pageNum: 1,
      select: '',
      searchInf: '',
      input3: ''
    }
  },
  async mounted() {
    this.getDrive()
  },
  methods: {
    async getDrive() {
      await request({
        method: 'get',
        url: '/prot/product-inspection/getAll/' + this.pageNum + '/5'
      }).then((response) => {
        console.log(response)
        this.mes = response.data.records
        for (let i = 0; i < this.mes.length; i++) {
          this.$set(this.mes[i], 'isShow', false)
          this.$set(this.mes[i], 'isShowDel', false)
        }
        this.pageSize = response.data.total
      })
    },
    async changeDriver(index) {
      console.log(this.mes[index])
      const driverLogistics = {
        'age': this.mes[index].age,
        'driverName': this.mes[index].driverName,
        'driverPhone': this.mes[index].driverPhone,
        'driverStatus': this.mes[index].driverStatus,
        'drivingAge': this.mes[index].drivingAge,
        'drivingLicenseNumber': this.mes[index].drivingLicenseNumber,
        'gender': this.mes[index].gender,
        'id': this.mes[index].id,
        'identityCard': this.mes[index].identityCard,
        'managementOfficeId': this.mes[index].managementOfficeId
      }
      console.log(driverLogistics)
      await request({
        method: 'put',
        url: '/zk/driverLogistics/update/' + this.mes[index].id,
        data: driverLogistics
      }).then(response => {
        console.log(response)
        if (response.statusCode == 20000) {
          this.dialogFormVisible = false
          this.addMes = {}
          this.$message({
            message: '修改成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，修改失败',
            type: 'warning'
          })
        }
      })
      this.getDrive()
      this.mes[index].isShow = false
    },
    async driveDel(index) {
      await request({
        method: 'delete',
        url: '/zk/driverLogistics/delete/' + this.mes[index].id
      }).then(response => {
        console.log(response)
        if (response.statusCode == 20000) {
          this.dialogFormVisible = false
          this.addMes = {}
          this.$message({
            message: '删除成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，添加失败',
            type: 'warning'
          })
        }
      })
      this.getDrive()
      this.mes[index].isShowDel = false
    },
    async addDri() {
      request({
        method: 'post',
        url: '/zk/driverLogistics',
        data: this.addMes
      }).then(response => {
        console.log(response)
        if (response.statusCode == 20000) {
          this.dialogFormVisible = false
          this.addMes = {}
          this.getDrive()
          this.$message({
            message: '添加成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，添加失败',
            type: 'warning'
          })
        }
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      this.pageNum = val
      request({
        method: 'get',
        url: '/zk/driverLogistics/get/' + val + '/5'
      }).then((response) => {
        console.log(response)
        this.mes = response.data.records
        for (let i = 0; i < this.mes.length; i++) {
          this.$set(this.mes[i], 'isShow', false)
          this.$set(this.mes[i], 'isShowDel', false)
        }
        this.pageSize = response.data.total
      })
    },
    searchMes() {
      if (this.select == 'id') {
        const data = {
          id: this.input3
        }
        request({
          url: '/zk/driverLogistics/get',
          method: 'post',
          data: data
        }).then(response => {
          if (response.statusCode == 20000) {
            this.$message({
              message: '查询成功',
              type: 'success'
            })
            console.log(response)
            this.mes = response.data
            for (let i = 0; i < this.mes.length; i++) {
              this.$set(this.mes[i], 'isShow', false)
              this.$set(this.mes[i], 'isShowDel', false)
            }
            this.pageSize = response.data.length
          } else {
            this.$message({
              message: '查无此人，查询失败',
              type: 'warning'
            })
          }
        })
      } else if (this.select == 'driverName') {
        const data = {
          driverName: this.input3
        }
        request({
          url: '/zk/driverLogistics/get',
          method: 'post',
          data: data
        }).then(response => {
          if (response.statusCode == 20000) {
            this.$message({
              message: '查询成功',
              type: 'success'
            })
            console.log(response)
            this.mes = response.data
            for (let i = 0; i < this.mes.length; i++) {
              this.$set(this.mes[i], 'isShow', false)
              this.$set(this.mes[i], 'isShowDel', false)
            }
            this.pageSize = response.data.length
          } else {
            this.$message({
              message: '查无此人，查询失败',
              type: 'warning'
            })
          }
        })
      } else if (this.select == 'drivingLicenseNumber') {
        const data = {
          drivingLicenseNumber: this.input3
        }
        request({
          url: '/zk/driverLogistics/get',
          method: 'post',
          data: data
        }).then(response => {
          if (response.statusCode == 20000) {
            this.$message({
              message: '查询成功',
              type: 'success'
            })
            console.log(response)
            this.mes = response.data
            for (let i = 0; i < this.mes.length; i++) {
              this.$set(this.mes[i], 'isShow', false)
              this.$set(this.mes[i], 'isShowDel', false)
            }
            this.pageSize = response.data.length
          } else {
            this.$message({
              message: '查无此人，查询失败',
              type: 'warning'
            })
          }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  height: 350px;
  // border: 1px solid black;
  display: flex;
  margin-bottom: 20px;
  justify-content: space-between;
}

.form {
    display: flex;
    flex-wrap: wrap;
    // border: 1px solid black;
    // justify-content: space-around;
}

.sel {
    width: 360px;
    display: flex;
    height: 50px;
    // border: 1px solid black;
    // border: 1px solid black;
    justify-content: flex-end;
    align-content: center;
    // border: 1px solid black;
}

.sel2 {
  width: 240px;
}

.page {
  width: 100%;
  display: flex;
  justify-content: right;
}

.imgDri {
  height: 300px;
  width: 400px;
}

.w1 {
  height: 80px;
  font-size: 25px;
  font-weight: 350;
}

.w2 {
  height: 50px;
  font-size: 15px;
  font-weight: 250;
}

.searchHead {
  display: flex;
  justify-content: space-between;
}

.searchIuput {
  width: 350px;
}

.sel3 {
  width: 100px;
}
</style>
